package commons.util;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import commons.entity.CpMissonResults;
import commons.entity.NativeCp;
import fgoScript.entity.panel.FgoFrame;
import fgoScript.exception.AppNeedStopException;
import gudaziEx.service.DownLoad;
import gudaziEx.service.HttpUtil;
import gudaziEx.util.ChainUtil;
import jodd.io.StreamGobbler;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.swing.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;


public class ProcessDealUtil {
	public static boolean ifSleep = true;
	private static final Logger LOGGER = LogManager.getLogger(ProcessDealUtil.class);

	/**
	 * @desc 启动进程
	 * @author zp
	 * @date 2018-3-29
	 */
	public static void startProc(String processName) {
		LOGGER.info("启动应用程序：" + processName);
		if (StringUtils.isNotBlank(processName)) {
			try {
				Desktop.getDesktop().open(new File(processName));
			} catch (Exception e) {
				LOGGER.error(e.getMessage(),e);
				LOGGER.error("应用程序：" + processName + "不存在！");
			}
		}
	}

	public static  void closeChrome() throws IOException {
			ProcessDealUtil.killProc("chrome.exe");
	}
	/**
	 * @desc 杀死进程
	 * @author zp
	 * @throws IOException
	 * @date 2018-3-29
	 */
	public static void killProc(String processName) throws IOException {
		LOGGER.info("关闭应用程序：" + processName);
		if (StringUtils.isNotBlank(processName)) {
			executeCmd("taskkill /F /IM " + processName,true);
		}
	}
	public static void startFgoByReplace(int account, int vms){
		// 打开雷电
		ProcessDealUtil.startLd(vms,false);

		//替换账号文件
		ReplaceAccountFile(account, vms);

		//启动fgo
		ProcessDealUtil.startAppWithOutClose(vms,false);

	}

	private static void ReplaceAccountFile(int account, int vms){
		boolean flag = true;
		while (flag){
			if(ProcessDealUtil.testLdRunning(vms)){
				flag =false;
			}else{
				GameUtil.delay(20 * 1000);

			}
		}
		ProcessDealUtil.cpAccountFileForFgo(account,vms);
	}
	/**
	 * @desc 执行cmd命令
	 * @author zp
	 * @date 2018-3-29
	 */
	public static void executeCmd(String command, boolean waitFlag) throws IOException {
		LOGGER.info("Execute command : " + command);
		Runtime runtime = Runtime.getRuntime();
		Process p = runtime.exec("cmd /c " + command);
		//等待执行完成
		if (waitFlag) {
			try {
				long before = System.currentTimeMillis();
				p.waitFor();
				long now = System.currentTimeMillis();
				LOGGER.info("命令执行了：" + (now - before) + " ms");
			} catch (InterruptedException e) {
				LOGGER.error(GameUtil.getStackMsg(e));
			}
		}
	}
	public static int executeCmdAndGetMsg(String command, boolean waitFlag) throws IOException, InterruptedException {
		int exitcode = -1;
		LOGGER.info("Execute command : " + command);
		Runtime runtime = Runtime.getRuntime();
		Process p = runtime.exec("cmd /c " + command);
		if (waitFlag) {
			exitcode = p.waitFor();
		}
		return exitcode;
	}
	/**
	 * @desc 执行cmd命令
	 * @author zp
	 * @date 2018-3-29
	 */
	public static void executeProcessBuilder(String command, boolean waitFlag) throws IOException {
		LOGGER.info("Execute command : " + command);
		ProcessBuilder processBuilder = new ProcessBuilder("cmd", "/c",
				"E:\\Game Files\\LDPlayer9\\adb.exe -s 127.0.0.1:5559 shell find /storage/emulated/0/Android/data/com.aniplex.fategrandorder/files/data -maxdepth 1 -type f -exec rm -f {} +");
		try {
			Process process = processBuilder.start();

			// 可以进一步处理进程的输入、输出和错误流
			// 例如：
			// BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
			// String line;
			// while ((line = reader.readLine()) != null) {
			//     System.out.println(line);
			// }

			int exitCode = process.waitFor(); // 等待进程执行完毕
			System.out.println("外部程序退出码: " + exitCode);

		} catch (IOException | InterruptedException e) {
			e.printStackTrace();
		}
	}
	/**
	 * @desc 判断进程是否开启
	 * @author zp
	 * @date 2018-3-29
	 */
	public static boolean findProcess(String processName) {
		BufferedReader bufferedReader = null;
		try {
			Process proc = Runtime.getRuntime().exec("tasklist -fi " + '"' + "imagename eq " + processName + '"');
			bufferedReader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
			String line;
			while ((line = bufferedReader.readLine()) != null) {
				if (line.contains(processName)) {
					return true;
				}
			}
			return false;
		} catch (Exception ex) {
			ex.printStackTrace();
			return false;
		} finally {
			if (bufferedReader != null) {
				try {
					bufferedReader.close();
				} catch (Exception ignored) {
				    LOGGER.error(ignored.getMessage(),ignored);
				}
			}
		}
	}




	public static void startAppForServerFgoSpace(int account, boolean ifcloseAll) {
		String url = getClientBaseUrlForServerFgoSpace();
		startAppDetail(account,ifcloseAll,url);
	}

	public static void downloadLastestFgo(){
		try {
			// get apkUrlhttps://apkpremier.com/download/com-aniplex-fategrandorder
			String url1 = "https://fgo.wiki/w/Mooncell:Jpclient";
			String url2 = HttpUtil.getHref(url1,"http://apk.fgo.wiki/Fate_GO");
			String version = url2.substring(url2.indexOf("-")+1,url2.length());

			// download apk from apkUrl1
			String path = NativeCp.getOneDriveDir()+"\\Code\\apk" + "\\com_aniplex_fategrandorder_v"+ version;
			DownLoad.downLoad(url2,path);
		} catch (AppNeedStopException e) {
			LOGGER.error(e.getMessage());
		}
	}
	public static void startTencentXriver(int account) {
		String url = getClientBaseUrl();
		String appName = "com.tencent.xriver";
		String line02 = url + "/dnconsole.exe  launchex --index " + account + " --packagename " +appName;
		killWerFault();
		closeLD(account);
		try {
			executeCmd(line02,false);
		} catch (IOException e) {
			LOGGER.error(e.getMessage(),e);
		}

	}
	public static void startDC(int account) {
		String url = getClientBaseUrl();
		String appName = "com.stairs.destinychild";
		String line02 = url + "/dnconsole.exe  launchex --index " + account + " --packagename " +appName;
		killWerFault();
		closeLD(account);
		try {
			executeCmd(line02,false);
		} catch (IOException e) {
			LOGGER.error(e.getMessage(),e);
		}

	}

	public static void startDCWithOutClose(int account) {
		String url = getClientBaseUrl();
		String appName = "com.stairs.destinychild";
		String line = url + "/dnconsole.exe  runapp --index " + account + " --packagename " +appName;
		killWerFault();
		try {
			executeCmd(line,false);
		} catch (IOException e) {
			LOGGER.error(e.getMessage(),e);
		}

	}
	public static void closeLD(int account) {
		GameUtil.colorMonitorList = null;
		String url = getClientBaseUrl();
		closeLDetail(account, url);
	}
	public static void closeLD(int account, String url) {
		GameUtil.colorMonitorList = null;
		closeLDetail(account, url);
	}

	public static void closeLDForServerFgoSpace(int account) {
		GameUtil.colorMonitorList = null;
		String url = getClientBaseUrlForServerFgoSpace();
		closeLDetail(account, url);
	}
	private static void closeLDetail(int account,String url){
		String closeLine ="\"" + url + "/dnconsole.exe"+"\""+"  quit --index " + account;
		try {
			executeCmd(closeLine,true);
		} catch (IOException e) {
			LOGGER.error(e.getMessage(),e);
		}
		GameUtil.delay(3000);
	}
	public static void startApp(int account,boolean ifcloseAll) {
		String url = getClientBaseUrl();
		startAppDetail(account,ifcloseAll,url);
	}
	private static void startAppDetail(int account,boolean ifcloseAll,String url){
		String appName = PropertiesUtil.getValueFromOpenFile("appName");
		String line = "\"" + url + "\\dnconsole.exe"+"\""+"  launchex --index " + account + " --packagename " +appName;
		killWerFault();
		closeLD(account, url);
		startdnplayer(line,ifcloseAll);
	}
	public static void startApp(int account,String appName, boolean ifcloseAll) {
		String url = getClientBaseUrl();
		String line = url + "/dnconsole.exe  launchex --index " + account + " --packagename " +appName;
		killWerFault();
		closeLD(account);
		startdnplayer(line,ifcloseAll);
	}
	public static void startAppWithOutClose(int account, boolean ifcloseAll) {
		String appName = PropertiesUtil.getValueFromOpenFile("appName");
		String url = getClientBaseUrl();
		String line = url + "/dnconsole.exe  launchex --index " + account + " --packagename " +appName;
		killWerFault();
		startdnplayer(line,ifcloseAll);
	}
	public static void startLd(int account, boolean ifcloseAll) {
		String url = getClientBaseUrl();
		String line = url + "/ldconsole.exe  launch --index " + account;
		String line2 = "\"" + url + "\\dnconsole.exe"+"\""+"  launch --index " + account;
		killWerFault();
		closeLD(account);
		startdnplayer(line2, ifcloseAll);

	}
	public static void startLdForServerFgoSpace(int account, boolean ifcloseAll) {
		String url = getClientBaseUrlForServerFgoSpace();
		String line = url + "/ldconsole.exe  launch --index " + account;
		killWerFault();
		closeLDForServerFgoSpace(account);
		startdnplayer(line, ifcloseAll);

	}
	private static String getClientBaseUrl(){
		String urlstring = GameUtil.getValueFromConfig("EXE_PATH");
		String[] urls = urlstring.split(";");
		int size = urls.length;
		File tempFile;
		String url = "";
		String tempUrl;
		for (int i = 0; i < size; i++) {
			tempUrl = urls[i];
			tempFile = new File(tempUrl);
			if(tempFile.exists()){
				url = tempUrl;
			}
		}
		return url;
	}
	public static String getConvertPath(String str){
		str.replaceAll(" ","\\");
		return null;
	}

	private static String getClientBaseUrlForServerFgoSpace(){
		String urlstring = GameUtil.getValueFromConfig("SEVER_FGO_EXE_PATH");
		String[] urls = urlstring.split(";");
		int size = urls.length;
		File tempFile;
		String url = "";
		String tempUrl;
		for (int i = 0; i < size; i++) {
			tempUrl = urls[i];
			tempFile = new File(tempUrl);
			if(tempFile.exists()){
				url = tempUrl;
			}
		}
		return url;
	}
	private static String getClientBaseUrlForNativeFgoSpace(){
		String urlstring = GameUtil.getValueFromConfig("EXE_PATH");
		String[] urls = urlstring.split(";");
		int size = urls.length;
		File tempFile;
		String url = "";
		String tempUrl;
		for (int i = 0; i < size; i++) {
			tempUrl = urls[i];
			tempFile = new File(tempUrl);
			if(tempFile.exists()){
				url = tempUrl;
			}
		}
		return url;
	}
	public static void installApp(int account) {
		String url = getClientBaseUrl();
		installAppInner(account, url);

	}
	public static void installAppForServerFgoSpace(int account) {
		String url = getClientBaseUrlForServerFgoSpace();
		installAppInner(account, url);

	}
	public static void installAppInner(int account, String url) {
		String appName = PropertiesUtil.getValueFromOpenFile("appName");
		String line = url + "/dnconsole.exe  installapp --index " + account + " --filename " + NativeCp.getOneDriveDir()+"\\Code\\apk\\" + getLatestFgoApkName();
		try {
			GameUtil.delay(10000);
			executeCmd(line,false);
		} catch (IOException e) {
			LOGGER.error(e.getMessage(),e);
		}
		line = url + "/dnconsole.exe  runapp --index " + account + " --packagename " +appName;
		try {
			GameUtil.delay(10000);
			executeCmd(line,false);
		} catch (IOException e) {
			LOGGER.error(e.getMessage(),e);
		}

	}
	public static String getLatestFgoApkName(){
		File listFile = new File(NativeCp.getOneDriveDir()+"\\Code\\apk");
		File[] apkList;
		String maxVersonName = "";
		if(listFile.isDirectory()){
			apkList = listFile.listFiles();
			int len = apkList.length;
			File tempFile;
			String fileName;
			int MaxVerson=0;
			int tempVerson;
			System.out.println("All Fgo Verson: ");
			for (int i = 0; i < len; i++) {
				tempFile = apkList[i];
				fileName = tempFile.getName();
				if(fileName.contains("crdownload")){
					GameUtil.delay(5 * 1000);
					return getLatestFgoApkName();
				}
				fileName = fileName.substring(fileName.indexOf("_v")+2,fileName.indexOf("_v")+8);
				System.out.println(fileName);
				fileName = fileName.replace(".","");
				tempVerson = Integer.parseInt(fileName);
				if(tempVerson > MaxVerson){
					MaxVerson = tempVerson;
					maxVersonName = tempFile.getName();
				}
			}
			System.out.println("Latest Fgo Verson Apk: ");
			System.out.println(maxVersonName);
		}
		return maxVersonName;
	}
	private static void startdnplayer(String line, boolean ifCloseAll) {
		String procName = "dnplayer.exe";
		boolean exist = findProcess(procName);
		try {
			if (exist && ifCloseAll) {
				// 存在，那么就先杀死该进程
				killProc(procName);
			}
			executeCmd(line,false);
		} catch (Exception e) {
			// TODO: handle exception
			LOGGER.error("重启/杀死提取程序失败。。。");
		}
	}
	public static void cpAccountFileForFgo(int account, int vms){
		String fromDir = "/mnt/shared/Pictures/fgo" + account + "/.";
		String toDir = "/storage/emulated/0/Android/data/com.aniplex.fategrandorder/files/data";
		delAllFilesForDes(vms,toDir);
		GameUtil.delay(1000);
		cpFileForDes(vms,fromDir,toDir);
		GameUtil.delay(1000);
	}
    public static void cpVmsFromOne() {

        String url = getClientBaseUrlForServerFgoSpace();

        String line = url + "/ldconsole.exe copy --from 1";
        try {
            executeCmd(line, true);
        } catch (IOException e) {
            LOGGER.error("拷贝程序失败。。。");
        }
    }
    public static void delVmsExcept1(){
		killAllDnPlayer();
        String url = getClientBaseUrlForServerFgoSpace();
//        url = getClientBaseUrl();
        for (int i = 2; i < 11; i++) {
//            String line = url + "/ldconsole.exe remove --index " + i;
			String line = "rmdir /s /q " + url +"\\vms\\leidian" + i;
//            String line = "G:/LDPlayer9/ldconsole.exe remove --index " + i;
//            String line = "rmdir /s /q G:/LDPlayer9/vms/leidian" + i;
            try {
                executeCmd(line, true);
            } catch (IOException e) {
                LOGGER.error("拷贝程序失败。。。");
            }
        }



    }

	public static void cpFileForDes(int vms, String fromDir, String toDir) {
		String commandOutput="";
		String vmsTypeStr;
		try {
			commandOutput = executeAdbCommand("devices", 5, TimeUnit.SECONDS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (commandOutput.contains("emulator")){
			vmsTypeStr = "emulator-";
		}else{
			vmsTypeStr = "127.0.0.1:";
		}
		String value0 = 5554+ + vms*2 + "";
		String value1 = 5555+ + vms*2 + "";
		int localVMaddr= 0;
		if(commandOutput.contains(value0)){
			localVMaddr = 5554;
		}else if (commandOutput.contains(value1)){
			localVMaddr = 5555;
		}
		int des = localVMaddr + vms*2;
		String url = getClientBaseUrlForNativeFgoSpace();

		String line = url + "/adb.exe -s " + vmsTypeStr + des + " shell cp -rf " + fromDir +" " + toDir;
		System.out.println(line);
		try {
			int code = 0;
			do {
				code = executeCmdAndGetMsg(line,true);
				GameUtil.delay(1000);
			} while (code != 0);
		} catch (IOException e) {
			LOGGER.error("拷贝程序失败。。。");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public static void delAllFilesForDes(int vms, String Dir) {
		String commandOutput="";
		String vmsTypeStr;
		try {
			commandOutput = executeAdbCommand("devices", 5, TimeUnit.SECONDS);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (commandOutput.contains("emulator")){
			vmsTypeStr = "emulator-";
		}else{
			vmsTypeStr = "127.0.0.1:";
		}
		String value0 = 5554+ + vms*2 + "";
		String value1 = 5555+ + vms*2 + "";
		int localVMaddr= 0;
		if(commandOutput.contains(value0)){
			localVMaddr = 5554;
		}else if (commandOutput.contains(value1)){
			localVMaddr = 5555;
		}
		int des = localVMaddr + vms*2;
		String url = getClientBaseUrlForNativeFgoSpace();

		String line = 	url + "\\adb.exe -s " + vmsTypeStr + des + " shell find " + Dir + " -maxdepth 1 -type f -exec rm -f {} +";
		System.out.println(line);
		try {
//			executeProcessBuilder(line, true);
			int code = 0;
			do {
				code = executeCmdAndGetMsg(line,true);
				GameUtil.delay(1000);
			} while (code != 0);

		} catch (IOException e) {
			LOGGER.error("删除文件失败。。。");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}

	public static void ReconectNet(String netName) {
		String line0= "netsh wlan disconnect";
		String line1= "netsh wlan connect name="+netName;
		try {
			executeCmd(line0,false);
			GameUtil.delay(2000);
			executeCmd(line1,false);
		} catch (IOException e) {
			LOGGER.error("关机失败");
		}
//		try {
//			killProc("java.exe");
//			LOGGER.info("关闭虚拟器");
//		} catch (IOException e) {
//			LOGGER.error(e.getMessage(),e);
//		}
	}
	public static void closeComputer() {
		closeComputerInTime( 2);
	}
	public static void closeComputerInTime(int minutes) {
		//登录关机状态
		CpMissonResults cr = CpMissonResults.getInstance();
		cr.setCpRunningState(false);
		ChainUtil.saveCpMissonResults(cr);

		int seconds = 60 * minutes;
		String line= "C:\\Windows\\System32\\shutdown.exe -s -t " + seconds;
		try {
			executeCmd(line,false);
			LOGGER.info(minutes + "分钟后关机《《》《》《》》");
		} catch (IOException e) {
			LOGGER.error("关机失败");
		}
		try {
			killProc("java.exe");
			LOGGER.info("关闭虚拟器");
		} catch (IOException e) {
            LOGGER.error(e.getMessage(),e);
        }
	}
	public static void sleepComputer() {

		sleepComputerIntime(5);
	}
	public static void runBatFiles(String batFilePath){
		try {
			LOGGER.info(NativeCp.getUserName()+" 执行Bat: "+ batFilePath);
			Process process = Runtime.getRuntime().exec(batFilePath);
			process.waitFor(); // 等待批处理执行完成
		} catch (IOException | InterruptedException e) {
			e.printStackTrace();
		}
	}
	public static void sleepComputerIntime(int seconds) {
		for (int i = 0; i < seconds; i++) {
			GameUtil.delay(1000);
			if(!ifSleep){
				break;
			}
		}
		if(ifSleep){
			String line1= "@echo off "+"timeout /t "+seconds+" && rundll32.exe powrprof.dll,SetSuspendState  0,1,0";
			String filePath = "C:\\Users\\Renzhehao\\OneDrive\\Code\\batchfile.bat";
			writeFile(line1,filePath);
			GameUtil.delay(1000);
			runBatFiles(filePath);

		}else{
			ifSleep = true;
			ProcessDealUtil.displayTray("休眠","计划的休眠已取消！", TrayIcon.MessageType.WARNING);
		}


	}
	public static void writeFile(String comments,String filePath){
		try {
			FileWriter writer = new FileWriter(filePath);
			writer.write(comments);
			writer.close();
			LOGGER.info(NativeCp.getUserName()+" 写入文件: "+ filePath +" 内容: "+ comments);

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	public static void abordCloseComputer() {
		String line= "C:\\Windows\\System32\\shutdown.exe -a";
		try {
			executeCmd(line,false);
		} catch (IOException e) {
			LOGGER.error("取消定时关机失败");
		}
	}

	public static void killAllDnPlayer() {
		String procName = "dnplayer.exe";
		boolean exist = findProcess(procName);
		try {
			if (exist) {
				// 存在，那么就先杀死该进程
				killProc(procName);
			}
		} catch (Exception e) {
			// TODO: handle exception
			LOGGER.error("重启/杀死提取程序失败。。。");
		}
	}
	public static void killAllDnPlayerNox() {
		String procName = "NoxVM.exe";
		boolean exist = findProcess(procName);
		try {
			if (exist) {
				// 存在，那么就先杀死该进程
				killProc(procName);
			}
		} catch (Exception e) {
			// TODO: handle exception
			LOGGER.error("重启/杀死提取程序失败。。。");
		}
	}
	public static void displayTray(String title, String message, TrayIcon.MessageType messageType) {
		ClassPathXmlApplicationContext applicationContext = MySpringUtil.getApplicationContext();
		FgoFrame f = (FgoFrame) applicationContext.getBean("fgoFrame");
		TrayIcon trayIcon = f.ti;
		if(null!=trayIcon){
			trayIcon.displayMessage(title, message, messageType);
		}
	}

	public static void killWerFault() {
		String procName = "WerFault.exe";
		boolean exist = findProcess(procName);
		try {
			if (exist) {
				// 存在，那么就先杀死该进程
				killProc(procName);
			}
		} catch (Exception e) {
			// TODO: handle exception
			LOGGER.error("重启/杀死提取程序失败。。。");
		}
	}
	public static String executeAdbCommand(String command, long timeout, TimeUnit unit) throws Exception {
		String url = ProcessDealUtil.getClientBaseUrlForNativeFgoSpace();
		ProcessBuilder processBuilder = new ProcessBuilder(url + "\\adb", command);
		Process process = processBuilder.start();

		// 启动一个单独的线程来监测进程是否在规定的时间内结束
		ExecutorService executor = Executors.newSingleThreadExecutor();
		Future<Boolean> future = executor.submit(() -> {
			try {
				process.waitFor();
				return true;
			} catch (InterruptedException e) {
				process.destroyForcibly();
				Thread.currentThread().interrupt();
				return false;
			}
		});

		// 等待进程结束或超时
		boolean completed = future.get(timeout, unit);
		executor.shutdownNow(); // 如果超时了，强制终止进程

		if (!completed) {
			throw new Exception("Command execution timed out.");
		}

		// 读取进程的输出
		BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
		StringBuilder output = new StringBuilder();
		String line;
		while ((line = reader.readLine()) != null) {
			output.append(line).append("\n");
		}
		reader.close();

		// 如果需要，处理错误流
		// BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
		// ...

		return output.toString();
	}
	public static boolean testLdRunning(int index){
		boolean button = true;
		boolean flag = false;

		String value0 = 5554+ + index*2 + "";
		String value1 = 5555+ + index*2 + "";
		while (button){
			try {
				String commandOutput = executeAdbCommand("devices", 5, TimeUnit.SECONDS);

				System.out.println(commandOutput);


				if(commandOutput.contains(value0) || commandOutput.contains(value1)){
					button= false;
					flag = true;
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
			GameUtil.delay(2000);

		}
		return flag;
	}


		public static void main(String[] args) {
//			try {
//				String msg = executeCmdAndGetMsg("E:\\LDPlayer9\\adb.exe -s 127.0.0.1:5559 shell find /storage/emulated/0/Android/data/com.aniplex.fategrandorder/files/data -maxdepth 1 -type f -exec rm -f {} +",false);
//				System.out.println("返回信息：" + msg);
//			} catch (IOException e) {
//				e.printStackTrace();
//			} catch (InterruptedException e) {
//				e.printStackTrace();
//			}
		}

}
